package com.codemonkey.lq.qd;


import com.codemonkey.lq.qd.builder.xml.XMLSConfigBuilder;
import com.codemonkey.lq.qd.facotry.config.SConfiguration;
import com.codemonkey.lq.qd.facotry.config.ServiceDefinition;
import com.codemonkey.lq.qd.facotry.config.ServiceFactory;
import com.codemonkey.lq.qd.utils.StringHelper;

/**
 * Spring中的配置方式:
 *    参见SpringMVCDemo项目
 * @author LQ
 *
 */
public final class XMLServiceFactory implements ServiceFactory {

	private final SConfiguration configuration;

	/**
	 * just from Spring. do not call yourself!!!
	 */
	public XMLServiceFactory() {
		configuration = null;
	}

	public XMLServiceFactory(String serviceXmlFilePath) {
		super();

		XMLSConfigBuilder builder = new XMLSConfigBuilder(serviceXmlFilePath);
		configuration = builder.build();
	}

	@Override
	public ServiceDefinition getService(String id) {
		if (StringHelper.isEmpty(id)) {
			return null;
		}
		return configuration.getServiceDefinition(id);
	}

}
